//package com.example.demo;
//
//import com.example.demo.auth.CustomAuthenticationProvider;
//import com.example.demo.auth.JWTAuthenticationFilter;
//import com.example.demo.auth.JWTLoginFilter;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.HttpMethod;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.config.http.SessionCreationPolicy;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//
//@Configuration
//@EnableWebSecurity
//@EnableGlobalMethodSecurity(prePostEnabled = true)
//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
//
//    private UserDetailsService userDetailsService;
//
//    private BCryptPasswordEncoder bCryptPasswordEncoder;
//
//    public WebSecurityConfig(UserDetailsService userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder) {
//        this.userDetailsService = userDetailsService;
//        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
//    }
//
//    // 设置 HTTP 验证规则
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        JWTLoginFilter jwtLoginFilter = new JWTLoginFilter(authenticationManager());
//        jwtLoginFilter.setFilterProcessesUrl("/v0.1/user/action/login");
//        http.cors().and().csrf().disable()
//                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
//                .authorizeRequests()
////                .antMatchers("/").permitAll()
//                .antMatchers("/v0.1/user/action/register", "/image/*").permitAll()
//                .anyRequest().authenticated()
//                .and()
//                .addFilter(jwtLoginFilter)
//                .addFilter(new JWTAuthenticationFilter(authenticationManager()))
//                .logout()
//                .logoutUrl("/logout")
//                .logoutSuccessUrl("/login")
//                .permitAll();
//    }
//
//    @Override
//    public void configure(AuthenticationManagerBuilder auth) throws Exception {
//        // 使用自定义身份验证组件
//        auth.authenticationProvider(new CustomAuthenticationProvider(userDetailsService, bCryptPasswordEncoder));
//    }
//
//}